package com.coldchain.cys.api;

import com.coldchain.authclient.annotation.CheckUserToken;
import com.coldchain.common.msg.BaseResponse;
import com.coldchain.common.msg.ObjectRestResponse;
import com.coldchain.cys.entity.Car;
import com.coldchain.cys.mapping.ApiUtils;
import com.coldchain.cys.page.CarQueryVo;
import com.coldchain.cys.service.ICarService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author tianpeng
 * @since 2018-08-28
 */
@RestController
@CheckUserToken
@Api(description="承运商系统车辆模块")
public class CarController {
	
	@Autowired
	private ICarService carService ;


	/**
	 * 查询车辆列表
	 * @param vo
	 * @return
	 */
	@GetMapping("/cys/car/list")
	public Object list(CarQueryVo vo){
		return new ObjectRestResponse<>().data(carService.searchForList(vo));
	}

	@GetMapping("/cys/car/getCarInfo/{id}")
	public Object getCarInfo(@PathVariable("id")String id){
		return new ObjectRestResponse<>().data(carService.getById(id)).succeed("ok");
	}
	/**
	 *获取车辆列表并分页面
	 * @param vo
	 * @return
	 */
	@GetMapping("/cys/car/list/page")
	public Object listPage(CarQueryVo vo){
		return new ObjectRestResponse<>().data(carService.search(vo)).succeed("ok");
	}
	@ApiIgnore
	@RequestMapping(value=ApiUtils.DO_SWITCH_CAR_USE + "/{carid}",method={RequestMethod.POST})
	public BaseResponse doSwitchCarUse(@PathVariable("carid") String carid){
		return carService.toggleStatus(carid) ;
	}
	
	@ApiOperation(value="根据车辆id")
	@ApiImplicitParams(value={
		@ApiImplicitParam(name="carid",value="车辆的id",dataType="Long",paramType="path"),
	})

	/**
	 * 添加或者修改车辆信息
	 * @param car
	 * @return
	 * @throws Exception
	 */
	@ApiIgnore
	@RequestMapping(value=ApiUtils.DO_ADD_OR_EDIT_CAR,method={RequestMethod.POST})
	public BaseResponse doAddOrEditCar(Car car) throws Exception{
		  return carService.edit(car);
	}
	
	@ApiOperation(value="后台审核车辆")
	@ApiImplicitParams(value={
		@ApiImplicitParam(name="carid",value="车辆的id",dataType="Long",paramType="query"),
	})
	@RequestMapping(value=ApiUtils.DO_EXAMINE_CAR,method={RequestMethod.POST})
	public BaseResponse doExamineCar(@ApiIgnore String carid){
		return carService.verify(carid);
	}

	/**
	 * 获取设备信息
	 * @param deviceNumber
	 * @return
	 */
	@GetMapping("/cys/car/getCarDeviceInfo")
	@CheckUserToken
	public BaseResponse getCarDeviceInfo( String deviceNumber){
		return  carService.getCarDeviceInfo(deviceNumber);
	}
//	@ApiOperation(value="司机上报位置")
//	@ApiImplicitParams(value={
//		@ApiImplicitParam(name="latitude",value="纬度",dataType="Double",paramType="query"),
//		@ApiImplicitParam(name="longitude",value="经度",dataType="Double",paramType="query"),
//	})
//	@RequestMapping(value=ApiUtils.REPORT_CAR_POSITION,method={RequestMethod.POST})
//	public RestResponse reportCarPosition(@ApiIgnore CarRouteLog carRouteLog){
//		return carService.reportCarPosition(carRouteLog) ;
//	}
	
//	@ApiOperation(value="查询车辆的行驶路径")
//	@ApiImplicitParams(value={
//		@ApiImplicitParam(name="pageNumber",value="页码",dataType="Integer",paramType="query"),
//		@ApiImplicitParam(name="carid",value="车辆的id",dataType="Long",paramType="query"),
//	})
//	@RequestMapping(value=ApiUtils.SHOW_CAR_ROUTE_LOG,method={RequestMethod.GET})
//	public ObjectRestResponse<Object> showCarRouteLog(@ApiIgnore CarRouteLog carRouteLog,
//			@ApiIgnore Integer pageNumber){
//		org.springframework.data.domain.Page<CarRouteLog> page = carService.showCarRouteLog(carRouteLog,pageNumber) ;
//		if(page == null){
//			return new ObjectRestResponse<Object>("获取失败") ;
//		}
//		return new ObjectRestResponse<Object>(page) ;
//	}


}
